/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Game;

import java.awt.Dimension;
import java.awt.Point;

/**
 *
 * @author
 */
public class GlobalSettings {
    public static int ScreenWidth = 1100;
    public static int ScreenHeight = 720;
    public static int CardHeight = (int)(ScreenHeight / 6);
    public static int CardWidth = (int)(CardHeight / 1.35);

    public static Dimension[] CardsDistances = new Dimension[]{
            new Dimension(60, 0),
            new Dimension(0, 25),
            new Dimension(25, 0),
            new Dimension(0, 25)};

    private static int BorderDistance = 40;

    public static Point[] PosToDraws = new Point[]{
            new Point((ScreenWidth - (12 * CardsDistances[0].width + CardWidth)) / 2, ScreenHeight - BorderDistance - CardHeight),
            new Point(BorderDistance + 3, BorderDistance + 25),
            new Point((ScreenWidth - (12 * CardsDistances[2].width + CardWidth)) / 2, BorderDistance + 25),
            new Point(ScreenWidth - 3 - BorderDistance - CardWidth, BorderDistance + 25)};

    public static Point[] PosToDrawName = new Point[]{
            new Point(PosToDraws[0].x + CardsDistances[0].width * 3, PosToDraws[0].y - 35),
            new Point(PosToDraws[1].x, PosToDraws[1].y - 15),
            new Point(PosToDraws[2].x, PosToDraws[2].y - 15),
            new Point(PosToDraws[3].x, PosToDraws[3].y - 15)};

    public static Dimension Transfer = new Dimension(50, 50);

    /**
     * Get x of point which has y
     * @param A : the first point
     * @param B : the second point
     * @param y : y of point which hasn't x
     * @return x coordinate
     */
    public static int getXInLine(Point A, Point B, int y)
    {
        // Viet phuong trinh duong thang qua 2 diem A(x1, y1) va B(x2, y2)
        // Vector chi phuong : AB(a, b) = (x1 - x2, y1 - y2)
        // Vector phap tuyen : n(-b,a) hoac n(b,-a)
        // x = x1 + a * t;
        // y = y1 + b * t;
        // ===> x = a/b * (y - y1) + x1
        // ===> y = b/a * (x - x1) + y1
        // Phương trình đường thẳng tổng quát qua M(x0,y0) có VTPT n(A,B)
        // A(x - x0) + B(y - y0) = 0

        //resulfPoint.x = A.x + directionVector.x * t;
        //resulfPoint.y = A.y + directionVector.y * t;

        int x = 0;

        Point directionVector = new Point(A.x - B.x, A.y - B.y);
        Point normalVector = new Point(-directionVector.y, directionVector.x);

        if (normalVector.x != 0 || normalVector.y != 0)
        {
            if (normalVector.x == 0)    // A = 0 ==> đường thằng y = y0
            {
                if (y == A.y)   // Nếu y = y0
                    x = A.x;    // trả về điểm đầu
                else
                    x = -5;     // y không thuộc đường
            }
            else
            {
                x = Math.round(-normalVector.y / normalVector.x * (y - A.y) + A.x);
            }
        }

        return x;
    }

    /**
     * Get y of point which has x
     * @param A : the first point
     * @param B : the second point
     * @param x : x of point which hasn't y
     * @return y coordinate
     */
    public static int getYInLine(Point A, Point B, int x)
    {
        int y = 0;

        Point directionVector = new Point(A.x - B.x, A.y - B.y);
        Point normalVector = new Point(-directionVector.y, directionVector.x);

        if (normalVector.x != 0 || normalVector.y != 0)
        {
            if (normalVector.y == 0)    // B = 0 ==> đường thằng x = x0
            {
                if (x == A.x)   // Nếu x = x0
                    y = A.y;    // trả về điểm đầu
                else
                    y = -5;     // y không thuộc đường
            }
            else
            {
                y = Math.round(((float)(-normalVector.x) / (float)normalVector.y) * (x - A.x)+ A.y);
            }
        }

        return y;
    }

    /**
     * Get distance between point A and point B
     */
    public static double getDistance(Point A, Point B)
    {
        double dX = A.x - B.x;
        double dY = A.y - B.y;
        return (Math.sqrt(Math.pow(dX, 2) + Math.pow(dY, 2)));
    }

    // Get transfer from point A to point B
    public static Dimension getTransfer(Point A, Point B)
    {
        Dimension d = new Dimension(0,0);

        // transfer on X axis
        if (B.x != A.x)
        {
            if (B.x < A.x)
                d.width = -Transfer.width;
            else
                d.width = Transfer.width;
        }

        // transfer on Y axis
        if (B.y != A.y)
        {
            if (B.y < A.y)
                d.height = -Transfer.height;
            else
                d.height = Transfer.height;
        }

        return d;
    }

    public static Point[] PosToDrawReceivedCard = new Point[]{
            new Point((ScreenWidth-CardWidth)/2,ScreenHeight/2+CardHeight/3),
            new Point((ScreenWidth-CardWidth)/2 - CardWidth*2, ScreenHeight/2 - CardHeight/2),
            new Point((ScreenWidth-CardWidth)/2,ScreenHeight/2 - CardHeight/3 - CardHeight),
            new Point((ScreenWidth-CardWidth)/2 + CardWidth*2,ScreenHeight/2 - CardHeight/2)};

    
}
